﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Net.Sockets;
using MyServer.Common;
using FrameWork.Setting;

namespace MyServer.Udp
{
    [SettingParentDefine]
    public class UdpDataListener : DataListenerBase
    {
        public override int CheckDataAvilable(object Client)
        {
            UdpClient C = (UdpClient)Client;
            return C.Available;
        }

        public override bool ClearData(object Client)
        {
            UdpClient C = (UdpClient)Client;
            IPEndPoint EP = new IPEndPoint(IPAddress.Any, 0);
            C.Receive(ref EP);
            return true;
        }

        public override bool AddConnect(object connect, bool CheckNow = true)
        {
            if (connect.GetType() == typeof(UdpPkgInfo))
            {
                return base.AddConnect(((UdpPkgInfo)connect).Client, CheckNow);
            }
            else
            {
                return base.AddConnect(connect, CheckNow);
            }
        }

        public UdpDataListener(UdpCenter Center)
            : base(Center)
        {
            base.ListenTimeOutValue = -1;
        }

    }
}
